
const app = getApp()
Page({
  data: {
    domainName: app.domainName,
    t1Id:1,
    tip:{ljxl:'hide'},
    orderActive:{a:'active', b:''}
  },
  onLoad: function (options) {
    console.log(options.id)
    this.setData({t1Id:options.id});
    var _this=this;
    wx.request({
      url: app.domainName + 'web/?c=userlist',
      method: 'POST',
      data: {id:options.id }, header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: function (res) {  
        _this.setData({userList:res.data});
          console.log(res)
      }});
    
  },
  goSearch(e) {
    var _this=this;
    var _searchName=this.data.searchName;
    if('' == _searchName){
      return;
    }
    wx.request({
      url: app.domainName + 'web/?c=search',
      method: 'POST',
      data: {n:_searchName }, header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: function (res) {  
        _this.setData({userList:res.data});
          console.log(res)
      }});
  },
  setinput(e) {
    this.setData({searchName:  e.detail.value});
  },
  goDetail(e) {
    var _id=e.currentTarget.dataset.id;
    wx.navigateTo({url: '/pages/jshao/index?id='+_id})
  },
  setOrder(e) {
    var _this=this;
    var _orderid=e.currentTarget.dataset.id;
    
    var _orderActive={a:'', b:''};
    if(1 == _orderid){
      _orderActive.a='active';
    }
    if(2 == _orderid){
      _orderActive.b='active';
    }
    _this.setData({orderActive:_orderActive});
    wx.request({
      url: app.domainName + 'web/?c=userlist',
      method: 'POST',
      data: {id:this.data.t1Id, oid:_orderid }, header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: function (res) {  
        _this.setData({userList:res.data});
      }});
  },
  goPop(e){
    var _id=e.currentTarget.dataset.id;
    if('openljlx' == _id){
      var _tip=this.data.tip;
      _tip.ljxl='';
      this.setData({tip:_tip});
      return;
    }
    if('closeljlx' == _id){
      var _tip=this.data.tip;
      _tip.ljxl='hide';
      this.setData({tip:_tip});
      return;
    }
    if('makephonecall' == _id){
      wx.makePhoneCall({
        phoneNumber: '13730908201'
      })
      return;
    }
    console.log(_id)
  },
  downQr(e){
    wx.downloadFile({
      url: app.domainName + 'img/qr.png',
      success (res) {
        if (res.statusCode === 200) {
          console.log(app.domainName + 'img/qr.png')
          console.log(res.tempFilePath)
            wx.saveImageToPhotosAlbum({
              filePath: res.tempFilePath,
              success(res) { 
                console.log(res)
              },
              complete(res) { 
                console.log(res)
              },
              fail: function (err) {
                if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err.errMsg === "saveImageToPhotosAlbum:fail authorize no response") {
                  // 这边微信做过调整，必须要在按钮中触发，因此需要在弹框回调中进行调用
                  wx.showModal({
                    title: '提示',
                    content: '需要您授权保存相册',
                    showCancel: false,
                    success: modalSuccess => {
                      wx.openSetting({
                        success(settingdata) {
                          console.log("settingdata", settingdata)
                          if (settingdata.authSetting['scope.writePhotosAlbum']) {
                            wx.showModal({
                              title: '提示',
                              content: '获取权限成功,再次点击图片即可保存',
                              showCancel: false,
                            })
                          } else {
                            wx.showModal({
                              title: '提示',
                              content: '获取权限失败，将无法保存到相册哦~',
                              showCancel: false,
                            })
                          }
                        },
                        fail(failData) {
                          console.log("failData", failData)
                        },
                        complete(finishData) {
                          console.log("finishData", finishData)
                        }
                      })
                    }
                  })
                }
              }
            })
        }
      }
    })
},
  onShareAppMessage: function () {

  }
})